
function ExampleType2(x) {
    this.x = x;
}

ExampleType2.prototype.someFunction = function(x) {
    this.x = x;
};

//----

// Code before OOP refactoring: global scope functions and variables

function workOnXyz(startWork) {
    if (startWork === true) {
        xyz = "New value";
    }
}

var xyz = "Some string value";// or null (var xyz=null;) or undefined (var xyz;)
workOnXyz(true);

//--- After refactoring: class scoped functions and variables

function ExampleClass(xyz) {
    this.xyz = xyz;
}

ExampleClass.prototype.workOnXyz = function(startWork) {
    if (startWork === true) {
        this.xyz = "New value";//Always use "this" prefix
    }
};

var exampleObj = new ExampleClass("Some string value");// This can be enywhere in code. Variable "exampleObj" is on global scope.
exampleObj.workOnXyz(true);

//----- Derived class

ExtendedExampleClass.prototype = new ExampleClass();
ExtendedExampleClass.prototype.constructor = ExtendedExampleClass;

function ExtendedExampleClass(xyz) {
    this.xyz = xyz;// TODO : is it possible to do in "super" like way?
}

ExtendedExampleClass.prototype.additionalFunc = function() {
    console.debug("Logger function with message:" + this.xyz);
};

var exampleObj2 = new ExtendedExampleClass("Some string value");
exampleObj2.additionalFunc();
exampleObj2.workOnXyz(true);
exampleObj2.additionalFunc();
